package com.tuling.jdk;

import com.tuling.UserInterface;
import com.tuling.UserService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyDemo {

	public static void main(String[] args) {
		UserService userService = new UserService();
		UserInterface userInterface = (UserInterface) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{UserInterface.class}, new InvocationHandler() {
			@Override
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
				System.out.println("before....");
				method.invoke(userService, args);
				System.out.println("after....");
				return null;
			}
		});
		userInterface.test();
	}
}
